package com.czb.server.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.czb.server.pojo.MenuRole;
import com.czb.server.mapper.MenuRoleMapper;
import com.czb.server.pojo.RespBean;
import com.czb.server.service.IMenuRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhanglishen
 * @since 2022-02-20
 */
@Service
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRole> implements IMenuRoleService {

    @Autowired
    private MenuRoleMapper menuRoleMapper;

    @Override
    @Transactional
    public RespBean updateMenuRole(Integer rid, Integer[] mids) {
        menuRoleMapper.delete(new QueryWrapper<MenuRole>().eq("rid", rid));
        if (null==mids || 0==mids.length)
            return RespBean.success("更新成功");

        return menuRoleMapper.insertRecord(rid,mids)==mids.length?RespBean.success("更新成功"):RespBean.error("更新失败");

    }
}
